<?php
class Controller_Login extends Controller_Abstract{
	
	function actionIndex(){
		$this->_view['isLogin'] = 0;
		
		if ( (int)$_SESSION['account_arr']['chk_uin'] > 0 ) {
			if (!empty($this->_context->redirect)) {
				return $this->_redirect( $this->_context->redirect );
			}else {
				$this->_view['isLogin'] = 100;
				$this->_view['user_id'] = $_SESSION['account_arr']['chk_uin'];
			}
		} //if session
		else{
			$this->_view['redirect'] = $this->_context->redirect;
		}
    }//END func Index
    
    function actionCheck(){
    	if( $_SESSION['checkcode'] == $this->_context->code ){
    		$query =  " CALL kexoo_im.sp_cklogin( '{$this->_context->user}', '{$this->_context->pswd}', 'password', '{$_SERVER['REMOTE_ADDR']}', 'notice' );";
	    	
    		$c = Q::ini('db_dsn_pool/default');
			$mysqli = new mysqli( $c['host'], $c['login'], $c['password']);
	    	$re = $mysqli->query($query);
	    	if (is_object($re)){
				$row = $re->fetch_assoc();
				$mysqli->next_result();
				$re->close();
			}
			$mysqli->close();

			if( $row['chk_uin'] == $this->_context->user ){
	    		$this->_view['isLogin'] = 100;
	    		$_SESSION['account_arr'] = $row; //mplat、之类
				unset ($_SESSION['checkcode']);
				
	    	}else $this->_view['isLogin'] = 102; //密码/用户名之一出错!
    	}else{
    		$this->_view['isLogin'] = 101; //效验码错误
    	}
    }
    
    function actionOut() {
//    	dump( Q::ini('db_dsn_pool/default') );
    	if( !empty($_SESSION) ){
    		foreach($_SESSION as $k=>$v){
    			unset($_SESSION[$k]);
    		}
    	}
    	return $this->_redirect( url('login/index') );
    }//END func logout
}//END class Login
?>